home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / cgraphix / histogrm.c < prev    next >
Text File  |  1986-05-28  |  3KB  |  136 lines

  1. /* «RM120»«PL99999»«TS4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76» */
  2. #include    <stdio.h>
  3. #define    EXTERN    extern
  4. #include    <typedef.h>
  5.  
  6.  
  7. static double s, Fract;
  8.  
  9.  
  10. static int Balance()
  11. {
  12.     int    Bal;
  13.  
  14.     Bal = 0;
  15.     s = s + Fract;
  16.     if (s >= 0.0) {
  17.         s = s - 1.0;
  18.         Bal = 1;
  19.     }
  20.     return(Bal);
  21. }
  22.  
  23.  
  24. void DrawHistogram(A, NPoints, Hatching, HatchStyle)
  25. double        *A;
  26. int            NPoints, Hatching, HatchStyle;
  27. {
  28.     extern double    fabs();
  29.  
  30.     int        x1, x2, y2, NPixels, Delta, NDiff, YRef;
  31.     int        LineStyleLoc, i;
  32.     int        YAxis;
  33.     double    y;
  34.     int        DirectModeLoc, Negative;
  35.     WindowType    wtemp;
  36.     int        X1Loc, Y1Loc, X2Loc, Y2Loc;
  37.  
  38.     if (iabs(NPoints) < 2) {
  39.         error(19,4);
  40.         return;
  41.     }
  42.  
  43.     X1Loc = X1Glb;
  44.     Y1Loc = Y1Glb;
  45.     X2Loc = X2Glb;
  46.     Y2Loc = Y2Glb;
  47.     LineStyleLoc = LineStyleGlb;
  48.     SetLineStyle(0);
  49.     if (AxisGlb) {
  50.         memcpy(&wtemp, &window[WindowNdxGlb], sizeof(WindowType));
  51.         ReDefineWindow(WindowNdxGlb, (int)(X1RefGlb + 4 + X1Glb),
  52.             (int)(Y1RefGlb + 6 + Y1Glb), (int)(X2RefGlb - 2 - X2Glb),
  53.             (int)(Y2RefGlb - 14 - Y2Glb));
  54.         SelectWindow(WindowNdxGlb);
  55.         AxisGlb = TRUE;
  56.     }
  57.     DirectModeLoc = DirectModeGlb;
  58.     DirectModeGlb = TRUE;
  59.     Negative = NPoints < 0;
  60.     NPoints = iabs(NPoints);
  61.     NPixels = (X2RefGlb-X1RefGlb) * 8 + 7;
  62.     Delta = NPixels / NPoints;
  63.     NDiff = NPixels - Delta * NPoints;
  64.     Fract = NDiff / NPoints;
  65.     s = -Fract;
  66.     x1 = X1RefGlb * 8;
  67.     YRef = (int)(Y2RefGlb+Y1RefGlb-AyGlb);
  68.     if (Negative)
  69.         DrawStraight(x1,X2RefGlb * 8 + 7,YRef);
  70.     YAxis = Y1RefGlb;
  71.     if (ByGlb > 0)
  72.         YAxis = Y2RefGlb;
  73.  
  74.     for (i = 0; i < 2 * NPoints; i+=2) {
  75.         x2 = x1 + Delta + Balance();
  76.         y = A[1 + i];
  77.         if (!Negative)
  78.             y = fabs(y);
  79. /*
  80.         if (AxisGlb)
  81.             y2 = (int)(AyGlb+ByGlb*y);
  82.         else
  83.             y2 = (int)((AyGlb+ByGlb*y)*0.99);
  84.         y2 = Y2RefGlb+Y1RefGlb-y2;
  85. */
  86.         y2 = Y2RefGlb + Y1RefGlb - (int)(AyGlb + ByGlb * y);
  87.  
  88.         if (!Negative) {
  89.             DrawLineDirect(x1, YAxis, x1, y2);
  90.             DrawStraight(x1,x2,y2);
  91.             DrawLineDirect(x2, y2, x2, YAxis);
  92.             if (Hatching) {
  93.                 if (i % 4)
  94.                     HatchDirect(x1, y2, x2, YAxis, HatchStyle);
  95.                 else
  96.                     HatchDirect(x1, y2, x2, YAxis, -HatchStyle);
  97.             }
  98.         }
  99.         else {
  100.             DrawLineDirect(x1, YRef, x1, y2);
  101.             DrawStraight(x1,x2,y2);
  102.             DrawLineDirect(x2, y2, x2, YRef);
  103.             if (Hatching) {
  104.                 if (YRef-y2 < 0) {
  105.                     if (i % 4)
  106.                         HatchDirect(x1, YRef, x2, y2, HatchStyle);
  107.                     else {
  108.                         HatchDirect(x1, YRef, x2, y2, -HatchStyle);
  109.                     }
  110.                 }
  111.                 else {
  112.                     if (i % 4)
  113.                         HatchDirect(x1, y2, x2, YRef, HatchStyle);
  114.                     else
  115.                         HatchDirect(x1, y2, x2, YRef, -HatchStyle);
  116.                 }
  117.             }
  118.             else
  119.                 HatchDirect(x1, y2, x2, YRef, -HatchStyle);
  120.         }
  121.         x1 = x2;
  122.     }
  123.     if (AxisGlb) {
  124.         memcpy(&window[WindowNdxGlb], &wtemp, sizeof(WindowType));
  125.         SelectWindow(WindowNdxGlb);
  126.         X1Glb = X1Loc;
  127.         Y1Glb = Y1Loc;
  128.         X2Glb = X2Loc;
  129.         Y2Glb = Y2Loc;
  130.         AxisGlb = FALSE;
  131.     }
  132.     DirectModeGlb = DirectModeLoc;
  133.     SetLineStyle(LineStyleLoc);
  134. }
  135.  
  136.